package itheima.com.Reader;

import java.io.*;

public class ObjectOutStream_ {

    public static void main(String[] args) {
//        ObjectOutStream objectOutStream = new ObjectOutputStream(new FileOutputStream("D:\\一条小团团\\data.dar"));

        try {
            ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\一条小团团\\data.dar"));
            oos.writeInt(100);
            oos.writeChar('a');
            oos.writeBoolean(true);
            oos.writeDouble(123.45);
            oos.writeByte('1');
            oos.writeUTF("小军吃呢");
            oos.writeObject(new Dog("旺财",12));
            oos.writeObject(new Dog("往往挖宝",22));

            oos.close();
            System.out.println("序列化完毕~~~");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}

class Dog implements Serializable{
    private String name;
    private int age;
    private String hobby;

    private Master master;
//serialVersionUID 序列化的版本号，可以提高兼容性
    private static final long serialVersionUID=1L;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}